import base64
from werkzeug.utils import secure_filename

class FileService():
    def __init__(self, req_str):
        info, self.data = req_str.split(',')
        _type, self.encoding = info.split(';')
        self.file_type, self.file_ext = _type.split(r'/')

    
    def save(self, file_name, path):
        fname = secure_filename(file_name)
        
        fpath = r'./' + path + r'/' + fname
        f = open(fpath, 'wb' )
        f.write(base64.b64decode(self.data))
        f.close()
